home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
yoonoGlobCommon.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
6KB
|
194 lines
/**
Global stuff for both yoono toolbar and side panel
@author : Xavier Grosjean
Copyright 2006, Yoono SAS.
**/
// XG: In order not to spread all global variables in the common environment, I keep them all
// inside an object. It's then much easier to find them with DomInspector
// however, I won't retro-apply this to all previous globs to avoid regression
var yoonoGlob = {};
yoonoGlob.flagDebug = true; // can be modified with Dom Inspector...
yoonoGlob.debug = function(msg) {
if (yoonoGlob.flagDebug) {
window.dump(msg + "\n");
}
}
var extId = '{d9284e50-81fc-11da-a72b-0800200c9a66}';
var extmgr = Components.classes['@mozilla.org/extensions/manager;1'].getService(Components.interfaces.nsIExtensionManager);
yoonoGlob.version = extmgr.getItemForID(extId).version;
yoonoGlob.WMED = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
yoonoGlob.scriptLoadingService = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
// Ouverture en fonction du choix de l'utilisateur en prefs
yoonoGlob.openUrlAccordingToPref = function(url, event, openMode) {
var pref = '';
try {
pref = YNPREFBRANCH.getCharPref("reco.display-mode");
} catch(e) {
pref = openMode;
}
if('defaults' == pref) pref = openMode;
switch (pref) {
case 'new-window':
yoonoGlob.openUrlInNewWindow(url, event);
break;
case 'current-window':
yoonoGlob.openUrlInCurrent(url, event);
break;
case 'new-tab':
yoonoGlob.openUrlInNewTab(url, event);
break;
// according to ff's default
default:
var win = yoonoGlob.WMED.getMostRecentWindow("navigator:browser");
win.openUILink(url, event, false, true);
break;
}
}
// Ouverture d'une URL dans le tab courant
yoonoGlob.openUrlInCurrent = function(url, event) {
var win = yoonoGlob.WMED.getMostRecentWindow("navigator:browser");
win.openUILinkIn(url, 'current');
}
// Ouverture d'une URL dans nouvo tab
yoonoGlob.openUrlInNewTab = function(url, event) {
try {
var win = yoonoGlob.WMED.getMostRecentWindow("navigator:browser");
var target = 'tab';
// on slow computers, the test below might result in overwritting
// a tab that should otherwise have been initialized to a start page
//var doc = win.getBrowser().contentDocument;
//var currentUrl = doc.location.href ;
//if('about:blank' == currentUrl) {
//target = 'current';
//}
win.openUILinkIn(url, target);
} catch(e) {
YOONO_LOG.exception(e);
}
}
// Ouverture d'une URL dans nouvelle fenetre
yoonoGlob.openUrlInNewWindow = function(url, event) {
var win = yoonoGlob.WMED.getMostRecentWindow("navigator:browser");
win.openUILinkIn(url, 'window');
}
yoonoGlob.openUrlWithHeaders = function(url, headers, event) {
var win = yoonoGlob.WMED.getMostRecentWindow("navigator:browser");
var nav = win.getWebNavigation();
var MIME_STREAM_CID = "@mozilla.org/network/mime-input-stream;1";
var nsIMIMEInputStream = YOONO_CI.nsIMIMEInputStream;
var mis = YOONO_CL[MIME_STREAM_CID];
var aHeaders = mis.createInstance(nsIMIMEInputStream);
for (var i in headers) {
aHeaders.addHeader(i, headers[i]);
}
// todo : open in tab according to mouse button. Pb : sending headers !
nav.loadURI(url, 0, null, null, aHeaders);
}
// Affichage d'un ptit bandeau indiquant le favori dont est issu le site proposΘ ou que synchro effectuΘe, ...
yoonoGlob.messageinfos = {
timer : Components.classes['@mozilla.org/timer;1'].createInstance(Components.interfaces.nsITimer),
delay : 10, // en secondes
message: function (browserparent) {
for (var i = browserparent.childNodes.length; i-- > 0;) {
if (browserparent.childNodes[i].nodeName == "yoonomessage")
return browserparent.childNodes[i];
}
return false;
},
showmessage: function (type, text1, text2) {
try {
var browser = getBrowser().selectedBrowser;
var browserParent = browser.parentNode;
var message = this.message(browserParent);
if (!message) {
yoonoGlob.debug('creation message');
message = document.createElement("yoonomessage");
browserParent.insertBefore(message, browser);
}
message.setAttribute('type', type);
message.text1 = text1;
if (text2) {
message.text2 = text2;
}
browser.isShowingMessage = true;
message.hidden = false;
var event = document.createEvent("Events");
event.initEvent("AlertActive", true, true);
message.dispatchEvent(event);
} catch(e) {
YOONO_LOG.exception(e);
}
},
hidemessage: function () {
var browser = getBrowser().selectedBrowser;
var browserParent = browser.parentNode;
var message = this.message(browserParent);
message.hidden = true;
},
init : function (type, text1, text2) {
try {
this.timer.cancel();
this.showmessage(type, text1, text2);
this.timer.init(this, this.delay * 1000, this.timer.TYPE_ONE_SHOT);
} catch(e) {
YOONO_LOG.exception(e);
}
},
observe : function(subject, topic, data) {
this.hidemessage();
}
}
// Fonction "surprise" qui ne bloque pas le navigateur
// pendant la recherche d'une suggestion (avec des retry et tout)
yoonoGlob.randomPageInit = function(evt, origin, openMode) {
try {
YOONO_CMPT.addStat(['clic', 'surprise', origin]);
// flag so that popups do not trigger the autorandom call
YOONO_CMPT._autorandomDone = true;
yoonoGlob.openUrlAccordingToPref('chrome://yoono/content/random.xul', evt, openMode);
} catch(e) {
YOONO_LOG.exception(e);
}
}
// Fonction appelΘe au lancement de FF si la pref autorandom est α true
// Attend que la synchro soit terminΘe
yoonoGlob.autorandom = function() {
// if done already, exit (popups)
if (YOONO_CMPT._autorandomDone) return;
YOONO_LOG.debug('Retrying autorandom');
// Wait for some stuff to be ready (namely list of bkms urls)
if(YOONO_CMPT.inprogress()) {
setTimeout(yoonoGlob.autorandom, 200);
return;
}
// flag so that popups do not trigger the autorandom call
YOONO_CMPT._autorandomDone = true;
YOONO_CMPT.addStat(['autosurprise']);
yoonoGlob.openUrlInNewTab('chrome://yoono/content/random.xul', null);
}